package cn.itcast.service.packing.impl;

import cn.itcast.dao.packing.InvoiceDao;
import cn.itcast.domain.packing.Invoice;
import cn.itcast.domain.packing.InvoiceExample;
import cn.itcast.service.packing.InvoiceService;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
@Service
public class InvoiceServiceImpl implements InvoiceService {

    @Autowired
    private InvoiceDao invoiceDao;

    @Override
    public List<Invoice> findAll(InvoiceExample example) {
        return invoiceDao.selectByExample(example);
    }

    @Override
    public Invoice findById(String id) {
        return invoiceDao.selectByPrimaryKey(id);
    }

    @Override
    public void save(Invoice invoice) {
    invoiceDao.insertSelective(invoice);
    }

    @Override
    public void update(Invoice invoice) {
    invoiceDao.updateByPrimaryKeySelective(invoice);
    }

    @Override
    public void delete(String id) {
        invoiceDao.deleteByPrimaryKey(id);
    }

    @Override
    public PageInfo findByPage(int pageNum, int pageSize, InvoiceExample example) {
        PageHelper.startPage(pageNum,pageSize);
        List<Invoice> invoiceList = invoiceDao.selectByExample(example);
        return new PageInfo<>(invoiceList);
    }
}
